package com.maxatime.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.maxatime.dao.DormitoryMapper;
import com.maxatime.dao.EmployeeInfoMapper;
import com.maxatime.dao.StudentDormitoryRelationMapper;
import com.maxatime.pojo.entity.Dormitory;
import com.maxatime.pojo.entity.EmployeeInfo;
import com.maxatime.pojo.entity.StudentDormitoryRelation;
import com.maxatime.service.DormitoryService;
import com.maxatime.util.SerialNumberUtil;

@Service
public class DormitoryServiceImpl implements DormitoryService{
	@Autowired
	DormitoryMapper dormitoryMapper;
	
	@Autowired
	EmployeeInfoMapper employeeInfoMapper;//讲师和班主任
	
	@Autowired
	StudentDormitoryRelationMapper studentDormitoryRelationMapper;//第二个表
	//查询
	@Override
	public List<Dormitory> listData(Dormitory dormitory) {
		// TODO Auto-generated method stub
		
		List<Dormitory> list = dormitoryMapper.listData(dormitory);
		return list;
	}
	//新增
	@Override
	public int insertSelective(Dormitory record) {
		// TODO Auto-generated method stub
		Dormitory dormitory = new Dormitory();
		BeanUtils.copyProperties(record, dormitory);
		Date d = new Date();
		dormitory.setCreateTime(d);
		dormitory.setUpdateTime(d);
		dormitory.setDeleteFlag("0");
		String dormitoryId=String.valueOf(SerialNumberUtil.getRandomNum());
		dormitory.setDormitoryId(dormitoryId);
		
//		StudentDormitoryRelation studentDormitoryRelation = new StudentDormitoryRelation();//第二个表
//		studentDormitoryRelation.setDormitoryDormitoryId(dormitoryId);
//		studentDormitoryRelation.setDeleteFlag("0");
//		studentDormitoryRelation.setCreateTime(d);
//		studentDormitoryRelation.setUpdateTime(d);
//		studentDormitoryRelationMapper.insertSelective(studentDormitoryRelation);
		dormitoryMapper.insertSelective(dormitory);
		return 0;
	}
	//查询管理员
	@Override
	public List<EmployeeInfo> gly(EmployeeInfo record) {
		// TODO Auto-generated method stub
		List<EmployeeInfo> list = employeeInfoMapper.teacher(record);
		return list;
	}
	//删除
	@Override
	public int deleteByPrimaryKey(Integer pkId) {
		// TODO Auto-generated method stub
		dormitoryMapper.deleteByPrimaryKey(pkId);
		return 0;
	}
	//反显
	@Override
	public Dormitory findpkId(Integer pkId) {
		// TODO Auto-generated method stub
		return dormitoryMapper.findpkId(pkId);
	}
	//修改
	@Override
	public int updateByPrimaryKeySelective(Dormitory record) {
		// TODO Auto-generated method stub
		Dormitory dormitory = new Dormitory();
		BeanUtils.copyProperties(record, dormitory);
		return dormitoryMapper.updateByPrimaryKeySelective(dormitory);
	}
	//跳转添加学生
	@Override
	public Dormitory select(Integer pkId) {
		// TODO Auto-generated method stub
		Dormitory dormitory = dormitoryMapper.select(pkId);
		
		return dormitory;
	}

}
